package net.hctek.identity.dao.impl;

import java.util.List;

import net.hctek.identity.bean.Files;
import net.hctek.identity.dao.FilesDaoI;
import net.hctek.identity.dao.base.impl.HibernateDaoImpl;



/** 
* @author Ken 384755534@qq.com: 
* @version 创建时间：2017年2月20日 下午2:06:32 
* 类说明 :
* 
*/
public class FilesDao extends HibernateDaoImpl implements FilesDaoI{

	//判断是否重复Files表
	@Override
	public List<String> selectFilesByName(String userId,String uploadFileName) {
		String hql = "select f.id from Files f where f.uploadFileName = '"+uploadFileName+"' and f.filepath like '%"+userId+"%'";
		return this.find(hql);
	}
	//判断是否重复中间表
	@Override
	public List<String> selectMiddleById(String id,String userid) {
		String hql = "select u from Files f INNER JOIN f.users u where f.id = '"+id+"' AND u.userId = '"+userid+"'";
		return this.find(hql);
	}
	//插入语句，原生SQL。
	@Override
	public Integer inserMiddleById(String id, String userid) {
		String hql = "insert into radiostudio_id_user_files(FILES_ID,USER_ID) values('"+id+"','"+userid+"')";
		int queryObject = getSession().createSQLQuery(hql).executeUpdate();
		return queryObject; 
	}
	//根据UserID查找对应的路径
	@Override
	public List<Files> selectFilePathById(String userid) {
		String hql = "select f.uploadFileName from Files f where f.filepath like '%"+userid+"%'";
		//String hql = "from Files f where f.filepath like '%"+userid+"%'";
		/*String hql = "select f from Files f INNER JOIN f.users u where u.userId = '"+userid+"' AND f.id = f.id";*/
		return this.find(hql);
	}
	public List<Files> repeatfile(String userId, String string) {
		String hql = "from Files f where f.filepath like '%"+userId+"%' and f.uploadFileName = '"+string+"'" ;
		return this.find(hql);
	}
	public List<String> getAll() {
		String userid = "admin";
		String hql = "select f from Files f INNER JOIN f.users u where u.userId = '"+userid+"' AND f.id = f.id";
		return this.find(hql);
	}

	
}
